# PowerShell script to build the ONNX Runtime library

Write-Host "Building ONNX Runtime library..."

# Create build directory if it doesn't exist
$buildDir = "onnxruntime\build"
if (!(Test-Path $buildDir)) {
    Write-Host "Creating build directory..."
    New-Item -ItemType Directory -Path $buildDir
}

# Change to build directory
Push-Location $buildDir

# Run CMake configuration
Write-Host "Running CMake configuration..."
cmake ..

if ($LASTEXITCODE -eq 0) {
    Write-Host "CMake configuration successful!"
    Write-Host "Building project..."
    
    # Build the project
    cmake --build . --config Release
    
    if ($LASTEXITCODE -eq 0) {
        Write-Host "Build successful!"
        
        # Return to root directory
        Pop-Location
        
        # Run setup script
        Write-Host "Running setup_libraries.bat..."
        .\setup_libraries.bat
    } else {
        Write-Host "Build failed!"
        Pop-Location
        exit 1
    }
} else {
    Write-Host "CMake configuration failed!"
    Pop-Location
    exit 1
}